import { createRouter, createWebHashHistory,createWebHistory } from 'vue-router';
import Layout from '@/layouts/index.vue';
import ParentView from '@/components/ParentView/index.vue';
import i18n from '@/locales';
const { global } = i18n;
export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录',
    },
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/errorPage/401.vue'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/errorPage/404.vue'),
    hidden: true,
  },
  {
    path: '/system',
    component: Layout,
    hidden:true,
    children: [
      {
        path: '/system/auth-user',
        name: 'authUser',
        component: () => import('@/views/system/role/authUser/index.vue'),
        meta: {
          title: global.t('route.authUser'),
          icon: 'icon-log',
        },
      },
      {
        path: '/system/user-role',
        name: 'userRole',
        component: () => import('@/views/system/user/authRole.vue'),
        meta: {
          title: global.t('route.userRole'),
          icon: 'icon-log',
        },
      },
      {
        path: '/system/dict-data',
        name: 'dictData',
        component: () => import('@/views/system/dict/data.vue'),
        meta: {
          title: global.t('route.dictData'),
          icon: 'icon-ad-product',
        },
      },
    ]
  },
  
];

export const asyncStaticRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: 'Root',
    children: [
      {
        path: '/index',
        name: 'Index',
        component: () => import('../views/index/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
]
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: 'Root',
    children: [
      {
        path: '/index',
        name: 'Index',
        component: () => import('../views/index/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  // {
  //   path: '/system',
  //   name: 'System',
  //   component: Layout,
  //   meta: {
  //     title: global.t('route.system'),
  //     icon: 'icon-setting',
  //   },
  //   children: [
  //     {
  //       path: '/system/user',
  //       name: 'User',
  //       component: () => import('@/views/system/user/index.vue'),
  //       meta: {
  //         title: global.t('route.user'),
  //         icon: 'icon-user',
  //       },
  //     },
  //     {
  //       path: '/system/role',
  //       name: 'Role',
  //       component: () => import('@/views/system/role/index.vue'),
  //       meta: {
  //         title: global.t('route.role'),
  //         icon: 'icon-people-safe',
  //       },
  //     },
  //     {
  //       path: '/system/menu',
  //       name: 'Menu',
  //       component: () => import('@/views/system/menu/index.vue'),
  //       meta: {
  //         title: global.t('route.menu'),
  //         icon: 'icon-tree-list',
  //       },
  //     },
  //     {
  //       path: '/system/dept',
  //       name: 'Dept',
  //       component: () => import('@/views/system/dept/index.vue'),
  //       meta: {
  //         title: global.t('route.dept'),
  //         icon: 'icon-branch-one',
  //       },
  //     },
  //     {
  //       path: '/system/post',
  //       name: 'Post',
  //       component: () => import('@/views/system/post/index.vue'),
  //       meta: {
  //         title: global.t('route.post'),
  //         icon: 'icon-waterfalls-v',
  //       },
  //     },
  //     {
  //       path: '/system/dict',
  //       name: 'Dict',
  //       component: () => import('@/views/system/dict/index.vue'),
  //       meta: {
  //         title: global.t('route.dict'),
  //         icon: 'icon-bookmark',
  //       },
  //     },
  //     {
  //       path: '/system/config',
  //       name: 'Cconfig',
  //       component: () => import('@/views/system/config/index.vue'),
  //       meta: {
  //         title: global.t('route.config'),
  //         icon: 'icon-setting-config',
  //       },
  //     },
  //     {
  //       path: '/system/notice',
  //       name: 'Notice',
  //       component: () => import('@/views/system/notice/index.vue'),
  //       meta: {
  //         title: global.t('route.notice'),
  //         icon: 'icon-comment',
  //       },
  //     },
  //     {
  //       path: '/system/log',
  //       name: 'Log',
  //       component: ParentView,
  //       meta: {
  //         title: global.t('route.log'),
  //         icon: 'icon-history',
  //       },
  //       children: [
  //         {
  //           path: '/monitor/operlog',
  //           name: 'Operlog',
  //           component: () => import('@/views/monitor/operlog/index.vue'),
  //           meta: {
  //             title: global.t('route.operlog'),
  //             icon: 'icon-clipboard',
  //           },
  //         },
  //         {
  //           path: '/monitor/logininfor',
  //           name: 'Logininfor',
  //           component: () => import('@/views/monitor/logininfor/index.vue'),
  //           meta: {
  //             title: global.t('route.logininfor'),
  //             icon: 'icon-log',
  //           },
  //         },
          
  //       ],
  //     },
      
  //   ],
  // },
  
  // {
  //   path: '/tool',
  //   name: 'Tool',
  //   component: Layout,
  //   meta: {
  //     title: global.t('route.tool'),
  //     icon: 'icon-components',
  //   },
  //   children: [
  //     {
  //       path: '/tool/upload',
  //       name: 'Upload',
  //       component: () => import('@/views/tool/upload/index.vue'),
  //       meta: {
  //         title: global.t('route.upload'),
  //         icon: 'icon-clipboard',
  //       },
  //     },
  //     {
  //       path: '/tool/gen',
  //       name: 'Gen',
  //       component: () => import('@/views/tool/gen/index.vue'),
  //       meta: {
  //         title: global.t('route.gen'),
  //         icon: 'icon-clipboard',
  //       },
  //     },
  //     {
  //       path: '/tool/swagger',
  //       name: 'Swagger',
  //       component: () => import('@/views/tool/swagger/index.vue'),
  //       meta: {
  //         title: global.t('route.swagger'),
  //         icon: 'icon-log',
  //       },
  //     },
  //     {
  //       path: '/tool/iconPark',
  //       name: 'IconPark',
  //       component: () => import('@/views/tool/iconPark/index.vue'),
  //       meta: {
  //         title: global.t('route.iconPark'),
  //         icon: 'icon-aiming',
  //       },
  //     },
      
  //   ],
   
  // },



// /monitor/online
// /monitor/job
// /monitor/druid
// /monitor/server
// /monitor/cache
// /tool/build
// /tool/gen
// /tool/swagger
// /monitor/operlog
// monitor/logininfor
  // {
  //   path: '/component',
  //   name: 'Component',
  //   component: Layout,
  //   meta: {
  //     title: global.t('route.component'),
  //     icon: 'icon-components',
  //   },
  //   children: [
  //     {
  //       path: '/list',
  //       name: 'List',
  //       component: () => import('@/views/list/index.vue'),
  //       meta: {
  //         title: global.t('route.list'),
  //         icon: 'icon-list',
  //       },
  //     },
  //     {
  //       path: '/userList',
  //       name: 'UserList',
  //       component: () => import('@/views/userList/index.vue'),
  //       meta: {
  //         title: global.t('route.userList'),
  //         icon: 'icon-user',
  //       },
  //     },
      
  //   ],
  // },
  
  {
    path: '/errorPage',
    name: 'ErrorPage',
    component: Layout,
    meta: {
      title: global.t('route.errorPages'),
      icon: 'icon-link-cloud-faild',
    },
    children: [
      {
        path: '/404Page',
        name: '404Page',
        component: () => import('@/views/errorPage/404.vue'),
        meta: {
          title: global.t('route.page404'),
          icon: 'icon-link-cloud-faild',
        },
      },
      {
        path: '/401Page',
        name: '401Page',
        component: () => import('@/views/errorPage/401.vue'),
        meta: {
          title: global.t('route.page401'),
          icon: 'icon-link-interrupt',
        },
      },
    ],
  },
  // {
  //   path: '*',
  //   redirect: '/404',
  //   hidden: true,
  // },
];


//createWebHistory  路由模式路径不带#号(生产环境下不能直接访问项目，需要nginx转发)
//createWebHashHistory  路由模式路径带#号
const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
});

// reset router
export function resetRouter() {
  router.getRoutes().forEach((route) => {
    const { name } = route;
    if (name) {
      router.hasRoute(name) && router.removeRoute(name);
    }
  });
}


export default router;
